package com.android.tools;

import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

public class DbUtils {

    public static void rawQuery(String sql, OnGetDataListener onGetDataListener) {
        SQLiteDatabase db = AndroidToolsConfig.androidToolsConfig.getDataBase();
        Cursor cursor = db.rawQuery(sql, null);
        if (null != cursor) {
            onGetDataListener.onGetDataListener(cursor);
            cursor.close();
        }
    }

    public interface OnGetDataListener {
        void onGetDataListener(Cursor cursor);
    }

    public static int getInt(Cursor cursor,String name){
        return cursor.getInt(cursor.getColumnIndex(name));
    }

    public static String getString(Cursor cursor,String name){
        return cursor.getString(cursor.getColumnIndex(name));
    }

    public static long getLong(Cursor cursor,String name){
        return cursor.getLong(cursor.getColumnIndex(name));
    }

    public static float getFloat(Cursor cursor,String name){
        return cursor.getFloat(cursor.getColumnIndex(name));
    }

    public static double getDouble(Cursor cursor,String name){
        return cursor.getDouble(cursor.getColumnIndex(name));
    }
}
